﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using MaxStudio.Concrete.Web;
using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server;
using MaxStudio.Concrete.Server.Service;
using MaxStudio.Concrete.Server.Dao;
using System.Configuration; 

namespace MaxStudio.Concrete.Web.Pages
{
    public partial class RPTAdmixtureReview : BasePage
    {
        string wholSequence = "LT/S实-12-01";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindGridView();
            }
        }
        #region Private Method

        private void BindGridView()
        {
            RPTAdmixtureReviewService RPTAdmixtureReviewServiceObj = ServiceFactory.getRPTAdmixtureReviewService();
            OperationResult<List<tb_RPT_AdmixtureReview>> result = RPTAdmixtureReviewServiceObj.GetAllAdmixtureReview();

            if (result.operationSuccess)
            {
                gvAdmixtureReviewList.DataSource = result.obj;
                gvAdmixtureReviewList.DataBind();
            }
            else
            {
                //EXCEPTION
                //return null;
            }
        }

        private void BindEdieDialog(int id)
        {
            RPTAdmixtureReviewService RPTAdmixtureReviewServiceObj = ServiceFactory.getRPTAdmixtureReviewService();
            OperationResult<tb_RPT_AdmixtureReview> resultEdit = RPTAdmixtureReviewServiceObj.GetAdmixtureReviewById(id);

            if (resultEdit.operationSuccess == true)
            {
                txtEditProjectName.Text = resultEdit.obj.ProjectName;
                txtEditAdditiveFactor.Text = resultEdit.obj.AdditiveFactor;
                txtEditOutSequence.Text = resultEdit.obj.OutSequence;
                txtEditInDate.Text = resultEdit.obj.InDate;
                txtEditTestDate.Text = resultEdit.obj.TestDate;
                txtEditCONTROLAppearance.Text = resultEdit.obj.CONTROLAppearance;
                txtEditCONTROLSolid.Text = resultEdit.obj.CONTROLSolid;
                txtEditCONTROLDensity.Text = resultEdit.obj.CONTROLDensity;
                txtEditCONTROLPH.Text = resultEdit.obj.CONTROLPH;
                txtEditCONTROLPulpFlowDegree.Text = resultEdit.obj.CONTROLPulpFlowDegree;
                txtEditCONTROLChlorineIon.Text = resultEdit.obj.CONTROLChlorineIon;
                txtEditMEASUAppearance.Text = resultEdit.obj.MEASUAppearance;
                txtEditMEASUSolid.Text = resultEdit.obj.MEASUSolid;
                txtEditMEASUDensity.Text = resultEdit.obj.MEASUDensity;
                txtEditMEASUPH.Text = resultEdit.obj.MEASUPH;
                txtEditMEASUPulpFlowDegree.Text = resultEdit.obj.MEASUPulpFlowDegree;
                txtEditMEASUChlorineIon.Text = resultEdit.obj.MEASUChlorineIon;
                txtEditTestStandard.Text = resultEdit.obj.TestStandard;
                txtEditTestResult.Text = resultEdit.obj.TestResult; ;
                txtEditRemark.Text = resultEdit.obj.Remark;
                txtEditReview.Text = resultEdit.obj.Review;
                txtEditApproval.Text = resultEdit.obj.Approval;
                txtEditTest.Text = resultEdit.obj.Test;

                lbLastModier.Text = "TEST";
                lbEidtId.Text = resultEdit.obj.Id.ToString();
                lbLastModifyDate.Text = resultEdit.obj.ModifyDate.ToShortDateString();
            }
        }

        private void DeleteRecords(int id)
        {
            lbDeleteId.Text = id.ToString();
        }

        #endregion

        #region Event

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            RPTAdmixtureReviewService RPTAdmixtureReviewServiceObj = ServiceFactory.getRPTAdmixtureReviewService();
            tb_RPT_AdmixtureReview instance = new tb_RPT_AdmixtureReview();
            instance.Sequence = wholSequence;
            instance.ProjectName = txtProjectName.Text; 
            instance.AdditiveFactor = txtAdditiveFactor.Text;
            instance.OutSequence = txtOutSequence.Text;
            instance.InDate = txtInDate.Text;
            instance.TestDate = txtTestDate.Text;
            instance.CONTROLAppearance = txtCONTROLAppearance.Text;
            instance.CONTROLSolid = txtCONTROLSolid.Text;
            instance.CONTROLDensity = txtCONTROLDensity.Text;
            instance.CONTROLPH = txtCONTROLPH.Text;
            instance.CONTROLPulpFlowDegree = txtCONTROLPulpFlowDegree.Text;
            instance.CONTROLChlorineIon = txtCONTROLChlorineIon.Text;
            instance.MEASUAppearance = txtMEASUAppearance.Text;
            instance.MEASUSolid = txtMEASUSolid.Text;
            instance.MEASUDensity = txtMEASUDensity.Text;
            instance.MEASUPH = txtMEASUPH.Text;
            instance.MEASUPulpFlowDegree = txtMEASUPulpFlowDegree.Text;
            instance.MEASUChlorineIon = txtMEASUChlorineIon.Text;
            instance.TestStandard = txtTestStandard.Text;
            instance.TestResult = txtTestResult.Text;
            instance.Remark = txtRemark.Text;
            instance.Review = txtReview.Text;
            instance.Approval = txtApproval.Text;
            instance.Test = txtTest.Text;

            OperationResult<tb_RPT_AdmixtureReview> result = RPTAdmixtureReviewServiceObj.CreateAdmixtureReview(instance);
            BindGridView();

        }
        protected void btnEdit_Click(object sender, EventArgs e)
        {
            int editId = 0;
            if (lbEidtId.Text.Length > 0)
            {
                editId = Int32.Parse(lbEidtId.Text);
            }

            RPTAdmixtureReviewService RPTAdmixtureReviewServiceObj = ServiceFactory.getRPTAdmixtureReviewService();
            tb_RPT_AdmixtureReview entity = new tb_RPT_AdmixtureReview();

            entity.Id = editId;
            entity.ProjectName =txtEditProjectName.Text;
            entity.AdditiveFactor =txtEditAdditiveFactor.Text;
            entity.OutSequence =txtEditOutSequence.Text;
            entity.InDate =txtEditInDate.Text;
            entity.TestDate =txtEditTestDate.Text;
            entity.CONTROLAppearance =txtEditCONTROLAppearance.Text;
            entity.CONTROLSolid =txtEditCONTROLSolid.Text;
            entity.CONTROLDensity =txtEditCONTROLDensity.Text;
            entity.CONTROLPH =txtEditCONTROLPH.Text;
            entity.CONTROLPulpFlowDegree =txtEditCONTROLPulpFlowDegree.Text;
            entity.CONTROLChlorineIon =txtEditCONTROLChlorineIon.Text;
            entity.MEASUAppearance =txtEditMEASUAppearance.Text;
            entity.MEASUSolid =txtEditMEASUSolid.Text;
            entity.MEASUDensity =txtEditMEASUDensity.Text;
            entity.MEASUPH =txtEditMEASUPH.Text;
            entity.MEASUPulpFlowDegree =txtEditMEASUPulpFlowDegree.Text;
            entity.MEASUChlorineIon =txtEditMEASUChlorineIon.Text;
            entity.TestStandard =txtEditTestStandard.Text;
            entity.TestResult =txtEditTestResult.Text;
            entity.Remark =txtEditRemark.Text;
            entity.Review =txtEditReview.Text;
            entity.Approval =txtEditApproval.Text;
            entity.Test =txtEditTest.Text;


            entity.ModifyDate = DateTime.Now;
            entity.ModifyBy = 1;
            entity.CreateDate = DateTime.Now;

            OperationResult<tb_RPT_AdmixtureReview> resultEdit = RPTAdmixtureReviewServiceObj.ModifyAdmixtureReview(entity);

            BindGridView();
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            int deleteId = Int32.Parse(lbDeleteId.Text);
            RPTAdmixtureReviewService RPTAdmixtureReviewServiceObj = ServiceFactory.getRPTAdmixtureReviewService();
            tb_RPT_AdmixtureReview deleteEntity = new tb_RPT_AdmixtureReview();

            deleteEntity.Id = deleteId;
            RPTAdmixtureReviewServiceObj.DeleteAdmixtureReview(deleteEntity);

            BindGridView();
        }

        protected void gvAdmixtureReviewList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
                string strSelectId = e.CommandArgument.ToString();
                BindEdieDialog(Int32.Parse(strSelectId));
            }

            if (e.CommandName == "del")
            {
                string strSelectId = e.CommandArgument.ToString();
                DeleteRecords(Int32.Parse(strSelectId));
            }
        }

        protected void gvAdmixtureReviewList_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvAdmixtureReviewList.PageIndex = e.NewPageIndex;
            BindGridView();
        }
        #endregion
    }
}
